package com.example.service.course;

import com.example.dao.course.CourseDao;
import com.example.enums.Status;
import com.example.pojo.Course;
import com.example.pojo.CourseRecord;
import com.example.pojo.ElementSelect;
import com.example.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CourseServeicImp implements CourseService{
    @Autowired
    private CourseDao courseDao;
    @Override
    public List<Course> getTable(Course course) {
        return courseDao.getTableData(course);
    }

    @Override
    public Status UpdateStatus(Integer id, Integer status) {
        boolean b = courseDao.UpdateStatus(id,status);
        if (b){
            return Status.OK;
        }else{
            return Status.Error;
        }
    }

    @Override
    public Course getCourseById(int courseId) {
        return courseDao.getCourseById(courseId);
    }

    @Override
    public boolean deleteCourse(int id) {
        return courseDao.deleteCourse(id);
    }

    @Override
    public List<CourseRecord> getRecordByCourseId(int CourseId) {
        return courseDao.getRecordByCourseId(CourseId);
    }

    @Override
    public List<ElementSelect> getUser(String name) {
        List<ElementSelect> list = new ArrayList<>();
        List<User> user = courseDao.getUser(name);
        for (User user1 : user) {
            ElementSelect elementSelect = new ElementSelect();
            elementSelect.setLabel(user1.getTrueName());
            elementSelect.setValue(user1.getUserId());
            list.add(elementSelect);
        }
        return list;
    }

    @Override
    public boolean updateCourse(Course course) {
        return courseDao.updateCourse(course);
    }

    @Override
    public boolean addCourse(Course course) {
        return courseDao.addCourse(course);
    }

}